package com.itheima;

import javax.print.attribute.HashDocAttributeSet;
import java.security.DrbgParameters;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @ProjectName: shixun DaErXia
 * @Titile: HashSetDemo
 * @Author: 雨
 * @Description: TODO
 */
public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("zgangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("lisi");
        list.add("lisi");
        list.add("lisi");
        System.out.println(list);
        ArrayList<String> newList=new ArrayList<>(new HashSet<String>(list));
        System.out.println(newList);

        //1.创建HashSet对象:不重复
        HashSet<String> hashSet =new HashSet<>();
        //2.保存数据
        hashSet.add("123");
        hashSet.add("456");
        hashSet.add("789");
        System.out.println(hashSet);
        //3.取数据(迭代器）
        Iterator<String> iterator = hashSet.iterator();
        while(iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        /**for(int i=0;i<hashSet.size();i++){
         * } 用不了
         */


        //4.取数据（增强for循环）
        for(String name:hashSet){
            System.out.println("name="+name);
        }

        int[] arr={1,2,3,4,5,6,7,8,9,10};
        for(int i:arr){
            System.out.println(i);
        }

        //5.取数据（lambda)
        hashSet.forEach(s-> System.out.println(s));
        hashSet.forEach(System.out::println);

        Student student=new Student("张三",28);
        System.out.println(student);

    }
}
